<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class goods extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'goods_name' => 'require|max:20',
        'vip'        => 'require|max:6|lt:price',
        'price'      => 'require|max:6|gt:vip',
        'default_image'=>  'fileExt:jpg,png,gif,jpeg|fileMime:image/jpg,image/png,image/gif,image/jpeg|fileSize:2097152',
        'cate_id'    => 'require',
        'brand'      => 'require',
    ];
    protected $field = [
        'goods_name' => '商品名称',
        'vip'        => 'VIP价格',
        'price'      => '商品价格',
        'default_image'=>  '图片',
        'cate_id'    => '分类',
        'brand'      => '品牌',
    ];
    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message = [
        'goods_name' => '商品名称不能超过20个字符',
        'vip'        => 'VIP价格小于商品价格',
        'price'      => '商品价格大于VIP价格',
        'cate_id'    => '分类必须选中',
        'brand'      => '品牌必须被选中',
        'default_image.fileExt'         => '只允许上传jpg，gif，png，jpeg后缀图片!',
    ];

    protected $scene = [
        'edit'  =>  ['goods_name', 'vip', 'price', 'cate_id', 'brand','default_image'],
    ];
}
